package com.cloudwise.controller;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author ：Teacher陈（86521760@qq.com）
 * @date ：Created in 2021/9/9 11:56
 * @description：第二个控制器
 * @modified By：
 * @version: 1.0
 */
public class YourServlet extends HttpServlet {

    public YourServlet() {
        System.out.println("servlet的构造方法被调用了");
    }

    @Override
    public void init() throws ServletException {
        System.out.println("servlet初始化了");
    }

    @Override
    public void destroy() {
        System.out.println("servlet销毁了");
    }


    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        ServletContext servletContext = super.getServletContext();
        String encoding = servletContext.getInitParameter("encoding");
        System.out.println("YourServlet全局参数encoding："+encoding);
        //获取局部参数
        String hobby = getInitParameter("hobby");
        System.out.println("YourServlet的爱好："+hobby);

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req,resp);
    }


}
